home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / CW GUSI 1.6.4 / include / sys⁄socket.h < prev    next >
Text File  |  1995-05-04  |  11KB  |  301 lines

  1. /*
  2.  * Copyright (c) 1982,1985,1986,1988 Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  *
  33.  *    @(#)socket.h    7.13 (Berkeley) 4/20/91
  34.  */
  35.  
  36. #ifndef _SYS_SOCKET_H_
  37. #define _SYS_SOCKET_H_
  38.  
  39. #include <compat.h>
  40.  
  41. /*
  42.  * Definitions related to sockets: types, address families, options.
  43.  */
  44.  
  45. /*
  46.  * Types
  47.  */
  48. #define    SOCK_STREAM        1        /* stream socket */
  49. #define    SOCK_DGRAM        2        /* datagram socket */
  50. #define    SOCK_RAW            3        /* raw-protocol interface */
  51. #define    SOCK_RDM            4        /* reliably-delivered message */
  52. #define    SOCK_SEQPACKET    5        /* sequenced packet stream */
  53.  
  54. /*
  55.  * Option flags per-socket.
  56.  */
  57. #define    SO_DEBUG            0x0001        /* turn on debugging info recording */
  58. #define    SO_ACCEPTCONN    0x0002        /* socket has had listen() */
  59. #define    SO_REUSEADDR    0x0004        /* allow local address reuse */
  60. #define    SO_KEEPALIVE    0x0008        /* keep connections alive */
  61. #define    SO_DONTROUTE    0x0010        /* just use interface addresses */
  62. #define    SO_BROADCAST    0x0020        /* permit sending of broadcast msgs */
  63. #define    SO_USELOOPBACK    0x0040        /* bypass hardware when possible */
  64. #define    SO_LINGER        0x0080        /* linger on close if data present */
  65. #define    SO_OOBINLINE    0x0100        /* leave received OOB data in line */
  66.  
  67. /*
  68.  * Additional options, not kept in so_options.
  69.  */
  70. #define SO_SNDBUF        0x1001        /* send buffer size */
  71. #define SO_RCVBUF        0x1002        /* receive buffer size */
  72. #define SO_SNDLOWAT    0x1003        /* send low-water mark */
  73. #define SO_RCVLOWAT    0x1004        /* receive low-water mark */
  74. #define SO_SNDTIMEO    0x1005        /* send timeout */
  75. #define SO_RCVTIMEO    0x1006        /* receive timeout */
  76. #define    SO_ERROR        0x1007        /* get error status and clear */
  77. #define    SO_TYPE        0x1008        /* get socket type */
  78.  
  79. /*
  80.  * Structure used for manipulating linger option.
  81.  */
  82. struct    linger {
  83.     int    l_onoff;            /* option on/off */
  84.     int    l_linger;        /* linger time */
  85. };
  86.  
  87. /*
  88.  * Level number for (get/set)sockopt() to apply to socket itself.
  89.  */
  90. #define    SOL_SOCKET    0xffff        /* options for socket level */
  91.  
  92. /*
  93.  * Address families.
  94.  */
  95. #ifdef macintosh
  96. #define    AF_UNSPEC         0        /* unspecified                                     */
  97. #define    AF_UNIX             1        /* local to host (pipes, portals)             */
  98. #define    AF_INET             2        /* internetwork: UDP, TCP, etc.                 */
  99. #define    AF_CTB             3        /* Apple Comm Toolbox (not yet supported) */
  100. #define    AF_FILE             4        /* Normal File I/O (used internally)        */
  101. #define    AF_PPC             5        /* PPC Toolbox                                        */
  102. #define    AF_PAP             6        /* Printer Access Protocol (client only)    */
  103. #define    AF_APPLETALK    16        /* Apple Talk                                         */
  104.  
  105. #define    AF_MAX        20
  106. #else
  107. #define    ATALK_SYMADDR 272        /* Symbolic Address for AppleTalk             */
  108. #define    AF_UNSPEC    0        /* unspecified */
  109. #define    AF_UNIX        1        /* local to host (pipes, portals) */
  110. #define    AF_INET        2        /* internetwork: UDP, TCP, etc. */
  111. #define    AF_IMPLINK    3        /* arpanet imp addresses */
  112. #define    AF_PUP        4        /* pup protocols: e.g. BSP */
  113. #define    AF_CHAOS        5        /* mit CHAOS protocols */
  114. #define    AF_NS            6        /* XEROX NS protocols */
  115. #define    AF_ISO        7        /* ISO protocols */
  116. #define    AF_OSI        AF_ISO
  117. #define    AF_ECMA        8        /* european computer manufacturers */
  118. #define    AF_DATAKIT    9        /* datakit protocols */
  119. #define    AF_CCITT        10        /* CCITT protocols, X.25 etc */
  120. #define    AF_SNA        11        /* IBM SNA */
  121. #define AF_DECnet        12        /* DECnet */
  122. #define AF_DLI            13        /* DEC Direct data link interface */
  123. #define AF_LAT            14        /* LAT */
  124. #define    AF_HYLINK    15        /* NSC Hyperchannel */
  125. #define    AF_APPLETALK16        /* Apple Talk */
  126. #define    AF_ROUTE        17        /* Internal Routing Protocol */
  127. #define    AF_LINK        18        /* Link layer interface */
  128. #define    pseudo_AF_XTP    19        /* eXpress Transfer Protocol (no AF) */
  129.  
  130. #define    AF_MAX        20
  131. #endif
  132.  
  133. /*
  134.  * Structure used by kernel to store most
  135.  * addresses.
  136.  */
  137. #if defined(powerc) || defined (__powerc)
  138. #pragma options align=mac68k
  139. #endif
  140. struct sockaddr {
  141.     u_char    sa_len;            /* total length */
  142.     u_char    sa_family;        /* address family */
  143.     char    sa_data[14];        /* actually longer; address value */
  144. };
  145. #if defined(powerc) || defined (__powerc)
  146. #pragma options align=reset
  147. #endif
  148.  
  149. /*
  150.  * Structure used by kernel to pass protocol
  151.  * information in raw sockets.
  152.  */
  153. struct sockproto {
  154.     u_short    sp_family;        /* address family */
  155.     u_short    sp_protocol;        /* protocol */
  156. };
  157.  
  158. /*
  159.  * Protocol families, same as address families for now.
  160.  */
  161. #ifdef macintosh
  162. #define    PF_UNSPEC         AF_UNSPEC        /* unspecified                                     */
  163. #define    PF_UNIX             AF_UNIX            /* local to host (pipes, portals)             */
  164. #define    PF_INET             AF_INET            /* internetwork: UDP, TCP, etc.                 */
  165. #define    PF_CTB             AF_CTB            /* Apple Comm Toolbox (not yet supported) */
  166. #define    PF_FILE             AF_FILE            /* Normal File I/O (used internally)        */
  167. #define    PF_PPC             AF_PPC            /* PPC Toolbox                                        */
  168. #define    PF_PAP             AF_PAP            /* Printer Access Protocol (client only)    */
  169. #define    PF_APPLETALK     AF_APPLETALK    /* Apple Talk                                         */
  170. #else
  171. #define    PF_UNSPEC    AF_UNSPEC
  172. #define    PF_UNIX        AF_UNIX
  173. #define    PF_INET        AF_INET
  174. #define    PF_IMPLINK    AF_IMPLINK
  175. #define    PF_PUP        AF_PUP
  176. #define    PF_CHAOS        AF_CHAOS
  177. #define    PF_NS            AF_NS
  178. #define    PF_ISO        AF_ISO
  179. #define    PF_OSI        AF_ISO
  180. #define    PF_ECMA        AF_ECMA
  181. #define    PF_DATAKIT    AF_DATAKIT
  182. #define    PF_CCITT        AF_CCITT
  183. #define    PF_SNA        AF_SNA
  184. #define PF_DECnet        AF_DECnet
  185. #define PF_DLI            AF_DLI
  186. #define PF_LAT            AF_LAT
  187. #define    PF_HYLINK    AF_HYLINK
  188. #define    PF_APPLETALK    AF_APPLETALK
  189. #define    PF_ROUTE        AF_ROUTE
  190. #define    PF_LINK        AF_LINK
  191. #define    PF_XTP        pseudo_AF_XTP    /* really just proto family, no AF */
  192. #endif
  193.  
  194. #define    PF_MAX        AF_MAX
  195.  
  196. /*
  197.  * Maximum queue length specifiable by listen.
  198.  */
  199. #define    SOMAXCONN    5
  200.  
  201. /*
  202.  * Message header for recvmsg and sendmsg calls.
  203.  * Used value-result for recvmsg, value only for sendmsg.
  204.  */
  205. struct msghdr {
  206.     caddr_t    msg_name;        /* optional address */
  207.     u_int        msg_namelen;        /* size of address */
  208.     struct    iovec *msg_iov;        /* scatter/gather array */
  209.     u_int        msg_iovlen;        /* # elements in msg_iov */
  210.     caddr_t    msg_control;        /* ancillary data, see below */
  211.     u_int        msg_controllen;        /* ancillary data buffer len */
  212.     int        msg_flags;        /* flags on received message */
  213. };
  214.  
  215. #define    MSG_OOB            0x1        /* process out-of-band data */
  216. #define    MSG_PEEK            0x2        /* peek at incoming message */
  217. #define    MSG_DONTROUTE    0x4        /* send without using routing tables */
  218. #define    MSG_EOR            0x8        /* data completes record */
  219. #define    MSG_TRUNC        0x10        /* data discarded before delivery */
  220. #define    MSG_CTRUNC        0x20        /* control data lost before delivery */
  221. #define    MSG_WAITALL        0x40        /* wait for full request or error */
  222.  
  223. /*
  224.  * Header for ancillary data objects in msg_control buffer.
  225.  * Used for additional information with/about a datagram
  226.  * not expressible by flags.  The format is a sequence
  227.  * of message elements headed by cmsghdr structures.
  228.  */
  229. struct cmsghdr {
  230.     u_int    cmsg_len;        /* data byte count, including hdr */
  231.     int    cmsg_level;        /* originating protocol */
  232.     int    cmsg_type;        /* protocol-specific type */
  233. /* followed by    u_char  cmsg_data[]; */
  234. };
  235.  
  236. /* given pointer to struct adatahdr, return pointer to data */
  237. #define    CMSG_DATA(cmsg)        ((u_char *)((cmsg) + 1))
  238.  
  239. /* given pointer to struct adatahdr, return pointer to next adatahdr */
  240. #define    CMSG_NXTHDR(mhdr, cmsg)    \
  241.     (((caddr_t)(cmsg) + (cmsg)->cmsg_len + sizeof(struct cmsghdr) > \
  242.         (mhdr)->msg_control + (mhdr)->msg_controllen) ? \
  243.         (struct cmsghdr *)NULL : \
  244.         (struct cmsghdr *)((caddr_t)(cmsg) + ALIGN((cmsg)->cmsg_len)))
  245.  
  246. #define    CMSG_FIRSTHDR(mhdr)    ((struct cmsghdr *)(mhdr)->msg_control)
  247.  
  248. /* "Socket"-level control message types: */
  249. #define    SCM_RIGHTS    0x01        /* access rights (array of int) */
  250.  
  251. /*
  252.  * 4.3 compat sockaddr, move to compat file later
  253.  */
  254. struct osockaddr {
  255.     u_short    sa_family;            /* address family */
  256.     char        sa_data[14];        /* up to 14 bytes of direct address */
  257. };
  258.  
  259. /*
  260.  * 4.3-compat message header (move to compat file later).
  261.  */
  262. struct omsghdr {
  263.     caddr_t    msg_name;            /* optional address */
  264.     int        msg_namelen;        /* size of address */
  265.     struct    iovec *msg_iov;    /* scatter/gather array */
  266.     int        msg_iovlen;            /* # elements in msg_iov */
  267.     caddr_t    msg_accrights;        /* access rights sent/received */
  268.     int        msg_accrightslen;
  269. };
  270.  
  271. #ifndef    KERNEL
  272.  
  273. #include <sys/cdefs.h>
  274.  
  275. __BEGIN_DECLS
  276. int    accept __P((int, struct sockaddr *, int *));
  277. int    bind __P((int, const struct sockaddr *, int));
  278. int    connect __P((int, const struct sockaddr *, int));
  279. int    getpeername __P((int, struct sockaddr *, int *));
  280. int    getsockname __P((int, struct sockaddr *, int *));
  281. int    getsockopt __P((int, int, int, void *, int *));
  282. int    listen __P((int, int));
  283. int    recv __P((int, void *, int, int));
  284. int    recvfrom __P((int, void *, int, int,
  285.         struct sockaddr *, int *));
  286. int    recvmsg __P((int, struct msghdr *, int));
  287. int    send __P((int, const void *, int, int));
  288. int    sendto __P((int, const void *, int, int, const struct sockaddr *, int));
  289. int    sendmsg __P((int, const struct msghdr *, int));
  290. int    setsockopt __P((int, int, int, const void *, int));
  291. int    shutdown __P((int, int));
  292. int    socket __P((int, int, int));
  293. #ifndef macintosh
  294. int    socketpair __P((int, int, int, int *));
  295. #endif
  296. __END_DECLS
  297.  
  298. #endif    /* !KERNEL */
  299.  
  300. #endif /* !_SYS_SOCKET_H_ */
  301.